<?php
include_once("_class.database.DBFactory.inc.php");

class DB{
	/**
	 * singleton db instance
	 * 
	 * @var IDatabase
	 */
	public static $dbs;
	
	/**
	 * get db instance
	 * 
	 * @return IDatabase
	 */
	public static function getInstance($confName="main"){
		if(!is_array(self::$dbs)) self::$dbs = array();
		if(array_key_exists($confName, self::$dbs)){
			return self::$dbs[$confName];
		}
		if(array_key_exists($confName, $_SERVER['config']['database'])){
			$conf = $_SERVER['config']['database'][$confName];
			if(!array_key_exists('type', $conf)){
				$conf['type'] = 'mysql';
			}
			self::$dbs[$confName] = DBFactory::createInstanceByConfiguration($conf);
			self::$dbs[$confName]->uppercase = 0;
			return self::$dbs[$confName];
		}else{
			return null;
		}
	}
}